﻿function writeObj(obj){
	var str = "";
	for(var i in obj){
		str = str + i + "          ";
	}
}
String.prototype.trim=function (){return this.replace((/(^\s*)|(\s*$)/img),'');}
String.prototype.isNumber=function (){return (/^[\+|\-]?\d*[\.]?\d*$/img).test(this);}
String.prototype.isInteger=function (){return (/^[\+|\-]?\d+$/img).test(this);}
String.prototype.isMoney=function (){return (/^[?|\$]?[\-|\+]?\s*\d*[\.]?\d*$/img).test(this);}
String.prototype.isDate=function (){return (/^(\w{4})(-|\/|.|)(\w{1,2})\2(\w{1,2})$/img).test(this);}
String.prototype.length2 = function() {
    var cArr = this.match(/[^x00-xff]/ig);
    return this.length + (cArr == null ? 0 : cArr.length);
}
String.prototype.isEmail=function ()
{
	return (/^([a-z][a-z0-9\_\.]*[a-z0-9])(@)(([a-z0-9][a-z0-9\-]*[a-z0-9][\.])+(com|cn|net|hk|tw|au|uk|de|tv|info|biz))$/img).test(this);
}
String.prototype.isPort=function (){
	if(!this.isInteger())return false;
	if(0 <= this.toNumber() && this.toNumber() <= 65535){
		return true;
	}else{
		return false;
	}
}
String.prototype.toNumber=function (){
	if(this.isInteger()) return parseInt(this);
	if(this.isNumber()) return parseFloat(this);
	return NaN;
}
String.prototype.inList=function(){
	for(var iCnt=0;iCnt<arguments.length;iCnt++)
		if(this==arguments[iCnt])
			return true;
	return false;
}
String.prototype.toMoneyValue=function (){
	if(!this.isMoney()) return NaN;
	return parseFloat(this.replace(/[?|\$]/img,''));
}
String.prototype.valueType=function (){
	if(this.isInteger()) return 'integer';
	if(this.isNumber()) return 'float';
	if(this.isMoney()) return 'money';
	return 'string';
}
String.prototype.replaceAll=function (findStr, repStr){
	var str = this;
	while(str.indexOf(findStr) > 0){
		str = str.replace(findStr, repStr);
	}
	return str;
}
function interceptStr(str_before)
{  
     //alert(str_before);
     //str_before = str_before.replaceAll(" ","") ;
     //alert(str_before);    
     if(str_before != "" && str_before != null && str_before != undefined)
     {
         var tmpStr=str_before.split("\r\n");
         //alert(tmpStr.length);
         return tmpStr;
     }
     return null;

}

function parseFloatNew(value)
{
    try{
        if(value == null || value == "")
        {
            return 0;
        }
        else if((value+"").isNumber())
        {
            return parseFloat(value);
        }
        return value;
    }catch(e){
    }
}

function fillSpace(value){
            if(value.length2() < 10){
                value ="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ value  + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
            }else{
                value ="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ value  + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp"
            }
            return value;
}


//New Add Function
//String.prototype.interceptAll=function()
//{
//    
//}
function isTel(s)   
{   
	//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;   
	var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;   
	if (!patrn.exec(s)) return false  
	return true  
}  

function isMobile(s)   
{   
	var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;   
	if (!patrn.exec(s+"")) return false  
	return true  
}   

function checkCard(cId){
	var pattern;
	if (cId.length==15){
		pattern= /^\d{15}$/;
		if (pattern.exec(cId)==null){
			return false;
		}
		if (!isDateString("19"+cId.substring(6,8) + "-" + cId.substring(8,10) + "-" + cId.substring(10,12))){
			return false;
		}
	}else if (cId.length==18){
		pattern= /^\d{17}(\d|x|X)$/;
		if (pattern.exec(cId)==null){
			return false;
		}
		if (!isDateString(cId.substring(6,10) + "-" + cId.substring(10,12) + "-" + cId.substring(12,14))){
			return false;
		}
		var strJiaoYan  =["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
		var intQuan =[7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
		var intTemp=0;
		for(i = 0; i < cId.length - 1; i++)
			intTemp +=  cId.substring(i, i + 1)  * intQuan[i];  
			intTemp %= 11;
		if(cId.substring(cId.length - 1,cId.length).toUpperCase()!=strJiaoYan[intTemp]){
			return false;
		}
	}else{
		return false;
	}
	return true;
}

function PhoneCheck(s) {
	var str = ""+s;
	var reg=/(^[0-9]{3,4}-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^([0-9]{3,4})[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;
	return reg.test(str);
}


function CovertCRLFToBR(s){ 
     var i; 
     var s2 = s; 
     while(s2.indexOf("\r\n")>0) { 
     	i = s2.indexOf("\r\n"); 
     	s2 = s2.substring(0, i) + "<br>" + s2.substring(i + 2, s2.length); 
     } 
     return s2; 
} 

function isDateString(sDate)
{    var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
    var iaDate = new Array(3)
    var year, month, day

    if (arguments.length != 1) return false
    iaDate = sDate.toString().split("-")
    if (iaDate.length != 3) return false
    if (iaDate[1].length > 2 || iaDate[2].length > 2) return false

    year = parseFloat(iaDate[0])
    month = parseFloat(iaDate[1])
    day=parseFloat(iaDate[2])

    if (year < 1900 || year > 2100) return false
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
    if (month < 1 || month > 12) return false
    if (day < 1 || day > iaMonthDays[month - 1]) return false
    return true
}


function checkDateEarlier(strStart,strEnd)
{
    if(isDateString(strStart) == false || isDateString(strEnd) == false)
        return false;
    
    if (( strStart == "" ) || ( strEnd == "" ))
        return true;
    var arr1 = strStart.split("-");
    var arr2 = strEnd.split("-");
    var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[2]);
    var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[2]);
    if(arr1[1].length == 1)
        arr1[1] = "0" + arr1[1];
    if(arr1[2].length == 1)
        arr1[2] = "0" + arr1[2];
    if(arr2[1].length == 1)
        arr2[1] = "0" + arr2[1];
    if(arr2[2].length == 1)
        arr2[2]="0" + arr2[2];
    var d1 = arr1[0] + arr1[1] + arr1[2];
    var d2 = arr2[0] + arr2[1] + arr2[2];
    if(parseInt(d1,10) > parseInt(d2,10))
       return false;
    else
       return true;
}

function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 1; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//读取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

